package com.whfc.ms.api.cfg.service.factory;

import com.alibaba.fastjson.JSON;
import com.whfc.common.exception.BizException;
import com.whfc.common.result.ResultEnum;
import com.whfc.fim.dto.FimAlgTypeDTO;
import com.whfc.fim.service.FimWarnRuleService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author qzexing
 * @version 1.0
 * @date 2021-07-30 16:48
 */
@Service(ConfigCenterServiceConstant.FIM_SERVICE)
public class ConfigCenterServiceFimImpl implements ConfigCenterService {

    @DubboReference(interfaceClass = FimWarnRuleService.class, version = "1.0.0")
    private FimWarnRuleService fimWarnRuleService;

    @Override
    public List getConfigList(Integer deptId, String module) {
        return fimWarnRuleService.algTypeList(deptId);
    }

    @Override
    public void setConfig(Integer deptId, String module, String dataStr) {
        List<FimAlgTypeDTO> algTypeList = JSON.parseArray(dataStr, FimAlgTypeDTO.class);
        if (algTypeList == null) {
            throw new BizException(ResultEnum.PARAM_ERROR.getCode(), "参数类型错误.");
        }
        fimWarnRuleService.algTypeConfigure(deptId, algTypeList);
    }

}

